package com.gitee.booting.balancer4j;

import lombok.Data;

import java.util.function.Function;

@Data
public abstract class Action<T, R> {
    private Exception exception;

    public Exception getException(Class<?> type) {
        return null != exception && type.isAssignableFrom(exception.getClass()) ? exception : null;
    }

    public abstract Function<T, R> what();

    public static <T, R> Action<T, R> of(Function<T, R> supplier) {
        return new Action<T, R>() {
            @Override
            public Function<T, R> what() {
                return supplier;
            }
        };
    }
}
